#ifndef __MESSAGE_MANAGER_H__
#define __MESSAGE_MANAGER_H__

#include <cstdint>
#include <string>
#include <memory>
#include "Utils/SensitiveFilter.h"

#include "SimpleSingleton.hpp"

namespace PocketSurvival
{
    class Client;
    typedef std::shared_ptr<Client> ClientPtr;

    class MessageManager : public SimpleSingletonItem
    {
        friend class SimpleSingleton;
    public:
        Utils::SensitiveFilter sensitiveFilter;
    private:
        MessageManager();
        ~MessageManager();
        MessageManager(const MessageManager &) = delete;
        MessageManager(MessageManager &&) = delete;
        MessageManager &operator=(const MessageManager &) = delete;
        MessageManager &operator=(MessageManager &&) = delete;

    public:
        /***********************************************************************************************************
         * @brief 处理消息，判断是否有敏感词或是否是指令
         * @param message 消息
         * @param client 客户端对象，nullptr时表示服务器自己
         * @return 是否可以转发, true：可以转发 | false:不能转发
        ***********************************************************************************************************/
        bool handleMessage(std::string &message, ClientPtr &client);


        /***********************************************************************************************************
         * @brief 过滤敏感词
         * @param content 要过滤的内容
         * @return 是否有敏感词，true: 有 | false: 没有
        ***********************************************************************************************************/
        inline bool filterContent(std::string &content);

        void load();
        void save();
    };

    inline bool MessageManager::filterContent(std::string &content)
    {
        return sensitiveFilter.filterContent(content);
    }
} // namespace PocketSurvival


#endif
